package com.ylsk.check.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ylsk.check.domain.dto.ChangeReportDTO;
import com.ylsk.check.domain.so.ChangeReportSO;
import com.ylsk.check.domain.vo.ChangeReportVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ylsk.common.annotation.Log;
import com.ylsk.common.core.controller.BaseController;
import com.ylsk.common.core.domain.AjaxResult;
import com.ylsk.common.enums.BusinessType;
import com.ylsk.check.domain.ChangeReport;
import com.ylsk.check.service.IChangeReportService;
import com.ylsk.common.utils.poi.ExcelUtil;
import com.ylsk.common.core.page.TableDataInfo;

/**
 * 变动上报Controller
 *
 * @author yangsy
 * @date 2024-01-08
 */
@RestController
@RequestMapping("/check/changeReport")
public class ChangeReportController extends BaseController
{
    @Autowired
    private IChangeReportService changeReportService;

    /**
     * 查询变动上报列表
     */
    @PreAuthorize("@ss.hasPermi('check:changeReport:list')")
    @GetMapping("/list")
    public TableDataInfo list(ChangeReportSO changeReportSO)
    {
        startPage();
        List<ChangeReportVO> list = changeReportService.selectChangeReportList(changeReportSO);
        return getDataTable(list);
    }

    /**
     * 导出变动上报列表
     */
    @PreAuthorize("@ss.hasPermi('check:changeReport:export')")
    @Log(title = "变动上报", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ChangeReportSO changeReportSO)
    {
        List<ChangeReportVO> list = changeReportService.selectChangeReportList(changeReportSO);
        ExcelUtil<ChangeReportVO> util = new ExcelUtil<ChangeReportVO>(ChangeReportVO.class);
        util.exportExcel(response, list, "变动上报数据");
    }

    /**
     * 获取变动上报详细信息
     */
    @PreAuthorize("@ss.hasPermi('check:changeReport:query')")
    @GetMapping(value = "/{changeReportId}")
    public AjaxResult getInfo(@PathVariable("changeReportId") Long changeReportId)
    {
        return success(changeReportService.selectChangeReportByChangeReportId(changeReportId));
    }

    /**
     * 新增变动上报
     */
    @PreAuthorize("@ss.hasPermi('check:changeReport:add')")
    @Log(title = "变动上报", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ChangeReportDTO changeReportDTO)
    {
        return toAjax(changeReportService.insertChangeReport(changeReportDTO));
    }

    /**
     * 修改变动上报
     */
    @PreAuthorize("@ss.hasPermi('check:changeReport:edit')")
    @Log(title = "变动上报", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ChangeReportDTO changeReportDTO)
    {
        return toAjax(changeReportService.updateChangeReport(changeReportDTO));
    }

    /**
     * 删除变动上报
     */
    @PreAuthorize("@ss.hasPermi('check:changeReport:remove')")
    @Log(title = "变动上报", businessType = BusinessType.DELETE)
	@DeleteMapping("/{changeReportIds}")
    public AjaxResult remove(@PathVariable Long[] changeReportIds)
    {
        return toAjax(changeReportService.deleteChangeReportByChangeReportIds(changeReportIds));
    }
}
